<?php

namespace App\Http\Controllers\Api\Web\Flight;

use App\Http\Controllers\Common\ApiController;
use App\Models\Flight\FlightInfo;
use Illuminate\Http\Request;

class FlightInfoController extends ApiController{

    private $model = FlightInfo::class;

    public function index(Request $request){
        dd(1111);
    }

    public function lst(Request $request) {

        $this->validate($request, [
            'key'=>'required'
        ],[],[
            'key'=>'查询信息'
        ]);

        $temp = explode('.', $request->input('key'));


        $lastName = $temp[0];
        $firstName = $temp[1];
        $orderNumber = $temp[2];
        if(empty($orderNumber)){
            return responseFail('请输入订单编号!');
        }

        $page = $request->input('page',1);
        $pageSize = $request->input('pageSize',1000);
        $conditions = compact('lastName','firstName','orderNumber');
        $records = (new $this->model())->getLst($conditions)
            ->with('getWriter:id,name')
            ->paginate($pageSize,$this->getCol,'page',$page);

        if($records->total()<=0){
            return responseFail('对不起，未查到相关订单！');
        }else{
            $conditions = compact('orderNumber');
            $records = (new $this->model())->getLst($conditions)
                ->with('getWriter:id,name')
                ->paginate($pageSize,$this->getCol,'page',$page);


            foreach ($records as $record) {
                $record->go_start_time = date('Y/m/d',strtotime($record->go_start_time));
                $record->passenger_sex= $record->passenger_sex==1?'男':'女';
                //$record->order_type= $record->order_type=='Eco'?'经济舱':'商务舱';
            }
            return responseSuccess($records->items(),$records->total());
        }




    }

    public function add(Request $request) {
        $info = $request->input();

        $this->validate($request, [

        ],[],[

        ]);

        $this->model::updateOrCreate(['id'=>$info['id']??0],$info);
    }

    public function detail(Request $request){
        $id = $request->input('id',0);
        $records = $this->getDetail($this->model,[$id]);
        return responseSuccess($records->toArray(),1);
    }

    public function change(Request $request) {

        $ids = $request->input('ids',[]);
        $status = $request->input('status');
        return $this->changeColByIds($this->model, [$ids],compact('status'));
    }

    public function del(Request $request) {
        $ids = $request->input('ids',[]);
        return $this->delRecords($this->model, $ids);
    }
}
